fix: remove Node-specific 'url' import from generated HTTP client#392
Merged
Conversation
✅ Deploy Preview for the-codegen-project canceled.
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
42413eb to
a463f7a
Compare
…lient URL and URLSearchParams are globals in Node.js and browsers; importing them from 'url' made generated packages fail to compile with TS2307 (Cannot find module 'url') unless the consumer had @types/node. With the node-fetch import already dropped in favor of the global fetch, generated HTTP clients now need no imports at all. Regenerated snapshots, runtime fixtures and the openapi-http-client example (the example also catches up with the native-fetch change, which had not regenerated it). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
a463f7a to
663c025
Compare
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
|
🎉 This PR is included in version 0.72.7 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The OpenAPI
http_clientchannel generator emitsimport { URLSearchParams, URL } from 'url';as a dependency of every generated HTTP client function.URLandURLSearchParamsare globals in both Node.js (since v10) and browsers, so the import is unnecessary — and it breaks compilation of generated packages that don't have@types/nodeinstalled:The native-fetch PR removed the
node-fetchimport but deliberately kept this one, so generated packages still failed to type-check without@types/node.Fix
Drop the
'url'import from the generated dependencies; combined with the native-fetch base, generated HTTP clients now emit no protocol-level imports at all. The generated code keeps using the globals unchanged.src/codegen/generators/typescript/channels/protocols/http/client.ts—dependenciesbecomes[]examples/openapi-http-clientgenerated output regenerated. Note: the example also catches up with the native-fetch change here, since that PR did not regenerate it.Verification
npm test— 50 suites, 623 passednpm run typecheckandnpm run typecheck:test— cleantscwithout@types/nodeafter this change; before it failed with TS2307.🤖 Generated with Claude Code